<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

//-----------------------------------------------------------------
//  Filter Acces Rightes
//-----------------------------------------------------------------

if(!isset($is_webmaster))
{ header("location: $PHP_SELF?i=2"); exit; }

//-----------------------------------------------------------------
//  Navigation Stuff
//-----------------------------------------------------------------

$rows_per_page = $config['nav_log'];
$numrows = $db->getInfo_countRows("log");

$lastpage = ceil($numrows/$rows_per_page);
$p = (int)$p;

if ($p < 1) $p = 1;
elseif ($p > $lastpage) $p = $lastpage;

if($numrows != FALSE) $limit = 'LIMIT ' .($p - 1) * $rows_per_page .',' .$rows_per_page;
else $limit = NULL;

//-----------------------------------------------------------------
//  Sorting Stuff
//-----------------------------------------------------------------

if(!isset($s)) $s = 'date'; // Default value
if(!isset($t)) $t = 'DESC'; // Default value

$sname1 = "date";
$sname2 = "date";
$sname3 = "user_user";
$sname4 = "log";

if($t == "ASC"){ $t = "DESC"; $t2 = "ASC"; }
else{ $t = "ASC"; $t2 = "DESC"; }

if($t == "ASC"){ $t3 = "<img src='templates/$template/images/misc/up.gif' border='0'>";}
else{ $t3 = "<img src='templates/$template/images/misc/down.gif' border='0'>";}

if($s == 1) $s = $sname1;
if($s == 2) $s = $sname2;
if($s == 3) $s = $sname3;
if($s == 4) $s = $sname4;

//-----------------------------------------------------------------
//  Load log table
//-----------------------------------------------------------------

$logs = $db->getTable("SELECT user_id, user_user, date, log FROM log ORDER BY ".$db->escape($s)." ".$db->escape($t2)." ".$db->escape($limit)."");

//-----------------------------------------------------------------
//  Make a foreach to separate the results
//-----------------------------------------------------------------

if($logs != FALSE)
{
	foreach($logs as $idx=>$log)
	{
		if($log['user_user'] == "Auto Protection") $log_user_user = $log['user_user'];
		else $log_user_user = "<a href='$PHP_SELF?n=modules/users&a=1&d={$log['user_id']}'>{$log['user_user']}</a>";

		//-----------------------------------------------------------------
		//  Make Layout
		//-----------------------------------------------------------------

		$layout .= "
			<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.location.href='$PHP_SELF?n=modules/users&a=1&d={$log['user_id']}'>
			<td><img src='templates/$template/images/status/stat".arrow_legend($log['date']).".gif' border='0' alt='".arrow_legend($log['date'])."'></td>
			<td align='center'>".today_yesterday($log['date'])."</td>
			<td>$log_user_user</td>
			<td>{$log['log']}</td>
			</tr>\n";

		//-----------------------------------------------------------------
		//  Start from 1
		//-----------------------------------------------------------------

		$idx++;
	}
}
else
{
	//-----------------------------------------------------------------
	//  Reset to 0
	//-----------------------------------------------------------------

	$idx = 0;

	//-----------------------------------------------------------------
	//  Make Layout
	//-----------------------------------------------------------------

	$layout .= "
		<tr class='con1'>
		<td colspan='5'>{$language['Loged Admin desc']}</td>
		</tr>\n";
}

//-----------------------------------------------------------------
//  Navigation Code
//-----------------------------------------------------------------

if($p == 1) $nav_prev = "<tr><td class='con1' align='right'>&nbsp;</td>";
else
{
	$prevpage = $p-1;
	$nav_prev = "<tr><td class='con1' align='left'><a href='$PHP_SELF?n=modules/admin-actions&s=$s&t=$t2&p=$prevpage'>&laquo; {$language['Loged Admin previous']}</a></td>";
}

$nav_nr = '[ '.paginate($lastpage, $p, $PHP_SELF.'?n=modules/admin-actions&s='.$s.'&t='.$t2).' ]';

if($idx == $numrows) $nav_nr = NULL;

if($p == $lastpage)
	$nav_next = "<td class='con1' align='right'>&nbsp;</td></tr>";
else
{
	$nextcode = $numrows - $idx * $p;
	if($nextcode > $idx) $how_next = $idx;
	else $how_next = $nextcode;

	$nextpage = $p+1;

	$nav_next = "<td class='con1' align='right'><a href='$PHP_SELF?n=modules/admin-actions&s=$s&t=$t2&p=$nextpage'>{$language['Loged Admin next']} $how_next &raquo;</a></td></tr>";
}

if($idx == $numrows)
{
	$nav_head = "class='con1'";
	$nav = NULL;
}
else
{
	$nav_head = "class='head'";
	$nav = ''.$nav_prev.''.$nav_next.'';
}

//-----------------------------------------------------------------
//  Start Layout + Navigation
//-----------------------------------------------------------------

?>
<table class="main" cellspacing="1" cellpadding="4">
<tr class='con1'><td><a href='<?= $PHP_SELF ?>?n=modules/admin'><?= $language['Admin name'] ?></a> &raquo; <?= $language['Loged Admin title'] ?></td></tr>
</table>
<table><tr><td></td></tr></table>	

<table class="main" cellspacing="1" cellpadding="4">
<tr class='head'><td colspan='5'><?= $language['Loged Admin title'] ?></td></tr>
<tr class="bottom">
<td width="1%" align="center"><a href="<?= $PHP_SELF ?>?n=modules/admin-actions&s=1&t=<?= $t ?>&p=<?= $p ?>"><? if($s == $sname1) echo $t3; else echo "*" ?></a></td>
<td width="15%"><a href="<?= $PHP_SELF ?>?n=modules/admin-actions&s=2&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Loged Admin title2'] ?> <? if($s == $sname2) echo $t3 ?></a></td>
<td width="15%"><a href="<?= $PHP_SELF ?>?n=modules/admin-actions&s=3&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Loged Admin title3'] ?> <? if($s == $sname3) echo $t3 ?></a></td>
<td width="69%"><a href="<?= $PHP_SELF ?>?n=modules/admin-actions&s=4&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Loged Admin title4'] ?> <? if($s == $sname4) echo $t3 ?></a></td>
</tr>
<?= $layout ?>
</table>
<table><tr><td></td></tr></table>	

<table class="main" cellspacing="1" cellpadding="4">
<col width="50%"><col width="50%">
<tr><td class="con1"><img src="templates/<?= $template ?>/images/status/stat1.gif" border="0"> <?= $language['Indicator1'] ?></td><td class="con1"><img src="templates/<?= $template ?>/images/status/stat3.gif" border="0"> <?= $language['Indicator3'] ?></td></tr>
<tr><td class="con1"><img src="templates/<?= $template ?>/images/status/stat2.gif" border="0"> <?= $language['Indicator2'] ?></td><td class="con1"><img src="templates/<?= $template ?>/images/status/stat4.gif" border="0"> <?= $language['Indicator4'] ?></td></tr>
</table>
<table><tr><td></td></tr></table>	

<table class="main" cellspacing="1" cellpadding="4" width="100%">
<col width="50%"><col width="50%">
<tr <?= $nav_head ?>>
<td colspan="2">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<col width="50%"><col width="50%">
<tr class="empty">
<td align="left"><?= $language['Loged Admin nav'] ?> <b><?= $idx ?></b> <?= $language['Loged Admin nav2'] ?> <b><?= $numrows ?></b></td>
<td align="right"><?= $nav_nr ?></td>
</tr>
</table>
</td>
</tr>
<?= $nav ?>
</table>